﻿<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
	if(isset($_SESSION['loggedin'])==FALSE){echo("<meta http-equiv=\"refresh\" content=\"0;url=login.php\">");}
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>聚合物产品工程科技创新团队药品管理软件|药品数据</title>
<link rel="stylesheet" type="text/css" href="reagentdb_data.css" />

</head>

<body>

<div class="container">
	<div class="header">
  	<img src="ypglhead.png" width="800" height="120" alt="标题" />
  </div>
  <div class="content">
    <h1><?php
  	//echo($_SESSION['user']);
	$_SESSION['ql']=$_GET['ql'];
	$_SESSION['qc']=$_GET['qc'];
	$_SESSION['qy']=$_GET['qy'];
  ?>
    </h1>
    <p>
    <div>
      <?php
  	require 'usercheck.php';
	//echo $currenttype;
	require "connectdb.php";
	/*$result = mysql_list_tables("polymer");

    if (!$result) {
        print "DB Error, could not list tables\n";
        print 'MySQL Error: ' . mysql_error();
        exit;
    }

    while ($row = mysql_fetch_row($result)) {
        print "Table: $row[0]\n";
    }*/
	echo "<p><div><form action='data.php' method='get'>";
	echo "<strong>搜索：</strong> 领用人<input type='text' name='ql' size='16'> 存放地点<input type='text' name='qc' size='16'> 药品名称<input type='text' name='qy' size='16'>";
	echo " <input type='submit' value='查询'> </form></div></p>";
	$result=NULL;
	if(isset($_SESSION['user'])){
		
		if($currenttype=='boss') $query="SELECT * FROM reagent_data WHERE (yc='1' or yc='0')";
		else  $query="SELECT * FROM reagent_data WHERE (admin='".$currentadmin."' or yc='0')";
	}
	if($_GET['ql']&&$_GET['ql']!='') $query=$query." AND lyr='".$_GET['ql']."'";
	if($_GET['qc']&&$_GET['qc']!='') $query=$query." AND cfd='".$_GET['qc']."'";
	if($_GET['qy']&&$_GET['qy']!='') $query=$query." AND ypmc like '%".$_GET['qy']."%'";
	//echo $query;
	$_SESSION['query']=$query;
	$result = mysql_query($query);
	echo "<table border='1' id='tables'>
				<tr><td>";
	if($currenttype=='boss'||$currenttype=='admin')echo "<a href='addnew.php'>";
	echo "新增+";
	if($currenttype=='boss'||$currenttype=='admin')echo "</a>";
	echo "		</td></tr>	
				<tr>
					<th>编号</th>
					<th>药品名称</th>
					<th>领用量</th>
					<th>领用日期</th>
					<th>存放地</th>
					<th>领用人</th>
					<th>核销日期</th>
					<th>经费号</th>
				</tr>";
$number=1;
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $number . "</td>";
  $number=$number+1;
  echo "<td>" . "<a href='detail.php?id=" . $row['id'] . "' ";
  if ($row['jd']=='1') echo"style='color:red'";
  else if ($row['dylyzd']=='1') echo "style='color:green'";
  echo " >" .$row['ypmc'] . "</a>" . "</td>";
  echo "<td>" . $row['lyl'] . "</td>";
  echo "<td>" . $row['lyrq'] . "</td>";
  echo "<td>" . $row['cfd'] . "</td>";
  echo "<td>" . $row['lyr'] . "</td>";
  echo "<td>" . $row['hxrq'] . "</td>";
  echo "<td>" . $row['jfh'] . "</td>";
  echo "<td>";
  if($currenttype=='boss'||$currenttype=='admin') echo "<a href='modify.php?id=".$row['id']."'>";
  echo "修改";
  if($currenttype=='boss'||$currenttype=='admin') echo "</a>";
  echo "</td>";
  echo "<td>";
  if($currenttype=='boss') echo "<a onClick=\"confirmDel('".$row['id']."','".$row['ypmc']."')\" href='#'>";
  echo "删除";
  if($currenttype=='boss') echo "</a>";
  echo "</td>";
  echo "</tr>";
  }
echo "</table>";
	
	if($currenttype=='boss') echo "<a href='changepwd.php'>修改密码 </a>";
	
	$result=mysql_query($query);
	$xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	$xml.="<root>";
	$counter=1;
	while($row=mysql_fetch_array($result)){
		$xml.="<row>";
		$xml.= "<编号>".$counter."</编号>";
		$xml.= "<药品名称>".$row['ypmc']."</药品名称>";
		$xml.= "<领用量>".$row['lyl']."</领用量>";
		$xml.= "<领用日期>".$row['lyrq']."</领用日期>";
		$xml.= "<存放地>".$row['cfd']."</存放地>";
		$xml.= "<领用人>".$row['lyr']."</领用人>";
		$xml.= "<核销日期>".$row['hxrq']."</核销日期>";
		$xml.= "<经费号>".$row['jfh']."</经费号>";
		$xml.= "<生产日期>".$row['scrq']."</生产日期>";
		$xml.= "<保质期>".$row['bzq']."</保质期>";
		$xml.= "<规格>".$row['gg']."</规格>";
		$xml.= "<生产商>".$row['scs']."</生产商>";
		$xml.= "<国别>".$row['gb']."</国别>";
		$xml.= "<供货商>".$row['ghs']."</供货商>";
		$xml.= "<管理员>".$row['admin']."</管理员>";
		$xml.="</row>";
		$counter=$counter+1;
	}
	$xml.="</root>";
	unlink("导出.xml");
	$file=fopen("导出.xml","w");
	fwrite($file,$xml);
	fclose($file);
	mysql_close($con);	
?>
	</div>
     </p>
      
    <p><a id="logout" href="logout.php">登出</a></p>
    <p><a href="导出.xml" target="_blank">EXCEL导出（请使用右键->目标另存为）</a></p>

    <!-- end .content --></div>
  <!-- end .container --></div>
<script type="text/javascript">
	function confirmDel(url,name){
		var del=confirm("确定要删除"+name+"吗？");
		if(del){
			window.open("delete.php?id="+url);
		}
	}
</script>
</body>
</html>